#pragma once

#include<iostream>

#include"agreement.h"
#include<map>

class TcpConnection;

class DirContral
{
private:
    /* data */
    //控制事件
    std::map<std::string,std::shared_ptr<CloudDrive::UploadControl>> downContral;
    std::mutex contralMutex;
    // 需要重新传的包 文件名+事件戳+id
    std::map<std::pair<std::string,uint32_t>,CloudDrive::FileInfoSave> fileData;
    std::mutex fileDataMutex;

    DirContral(const DirContral&)            = delete;
    DirContral& operator=(const DirContral&) = delete;

    // （可选）C++11 还可以禁用移动构造和移动赋值
    DirContral(DirContral&&)                 = delete;
    DirContral& operator=(DirContral&&)      = delete;
    

public:
    DirContral(/* args */);
    ~DirContral();

    static DirContral & getInstance();
    //新建文件夹子
    bool directoryExists(std::string filePath);
    bool isFileExist(const std::string &path);
    
    //返回文件夹列表
    CloudDrive::MesBackFile getFileList(const std::string filePath);
    //创建新的文件夹
    CloudDrive::MessageReturn creatNewFolder(std::string filePath);
    //删除文件夹
    CloudDrive::MessageReturn deleteFolder(std::string filePath);
    // 删除文件
    bool removeDirectoryRecursively(const std::string& path);

    //写文件
    bool writeDataToFile(const std::string& filePath, 
                    const std::vector<uint8_t>& data, 
                    uint64_t offset,
                    std::mutex &fileMutex,
                    bool createIfNotExist = true);
    //下载文件
    void downLoadFile(const std::string &fileName,const std::string &filePath,
                    const std::string & fileIdenter,
                std::shared_ptr<TcpConnection> conn);  

    void fileDownSet(std::string,std::string);
};

